\usepackage{hyperref} %超链接
\usepackage{color} %颜色
\usepackage{listings}%代码
\usepackage{fancyhdr} % 支持自定义的页眉、页脚
\usepackage{fancyvrb} % 支持抄录
\usepackage{graphicx}
\usepackage{framed}
\definecolor{shadecolor}{gray}{0.85}%used for shade mini page
%------------------颜色---------------------------------------
\definecolor{GreenYellow}{cmyk}{0.15,0,0.69,0}
\definecolor{Yellow}{cmyk}{0,0,1,0}
\definecolor{Goldenrod}{cmyk}{0,0.10,0.84,0}
\definecolor{Dandelion}{cmyk}{0,0.29,0.84,0}
\definecolor{Apricot}{cmyk}{0,0.32,0.52,0}
\definecolor{Peach}{cmyk}{0,0.50,0.70,0}
\definecolor{Melon}{cmyk}{0,0.46,0.50,0}
\definecolor{YellowOrange}{cmyk}{0,0.42,1,0}
\definecolor{Orange}{cmyk}{0,0.61,0.87,0}
\definecolor{BurntOrange}{cmyk}{0,0.51,1,0}
\definecolor{Bittersweet}{cmyk}{0,0.75,1,0.24}
\definecolor{RedOrange}{cmyk}{0,0.77,0.87,0}
\definecolor{Mahogany}{cmyk}{0,0.85,0.87,0.35}
\definecolor{Maroon}{cmyk}{0,0.87,0.68,0.32}
\definecolor{BrickRed}{cmyk}{0,0.89,0.94,0.28}
\definecolor{Red}{cmyk}{0,1,1,0}
\definecolor{OrangeRed}{cmyk}{0,1,0.50,0}
\definecolor{RubineRed}{cmyk}{0,1,0.13,0}
\definecolor{WildStrawberry}{cmyk}{0,0.96,0.39,0}
\definecolor{Salmon}{cmyk}{0,0.53,0.38,0}
\definecolor{CarnationPink}{cmyk}{0,0.63,0,0}
\definecolor{Magenta}{cmyk}{0,1,0,0}
\definecolor{VioletRed}{cmyk}{0,0.81,0,0}
\definecolor{Rhodamine}{cmyk}{0,0.82,0,0}
\definecolor{Mulberry}{cmyk}{0.34,0.90,0,0.02}
\definecolor{RedViolet}{cmyk}{0.07,0.90,0,0.34}
\definecolor{Fuchsia}{cmyk}{0.47,0.91,0,0.08}
\definecolor{Lavender}{cmyk}{0,0.48,0,0}
\definecolor{Thistle}{cmyk}{0.12,0.59,0,0}
\definecolor{Orchid}{cmyk}{0.32,0.64,0,0}
\definecolor{DarkOrchid}{cmyk}{0.40,0.80,0.20,0}
\definecolor{Purple}{cmyk}{0.45,0.86,0,0}
\definecolor{Plum}{cmyk}{0.50,1,0,0}
\definecolor{Violet}{cmyk}{0.79,0.88,0,0}
\definecolor{RoyalPurple}{cmyk}{0.75,0.90,0,0}
\definecolor{BlueViolet}{cmyk}{0.86,0.91,0,0.04}
\definecolor{Periwinkle}{cmyk}{0.57,0.55,0,0}
\definecolor{CadetBlue}{cmyk}{0.62,0.57,0.23,0}
\definecolor{CornflowerBlue}{cmyk}{0.65,0.13,0,0}
\definecolor{MidnightBlue}{cmyk}{0.98,0.13,0,0.43}
\definecolor{NavyBlue}{cmyk}{0.94,0.54,0,0}
\definecolor{RoyalBlue}{cmyk}{1,0.50,0,0}
\definecolor{Blue}{cmyk}{1,1,0,0}
\definecolor{Cerulean}{cmyk}{0.94,0.11,0,0}
\definecolor{Cyan}{cmyk}{1,0,0,0}
\definecolor{ProcessBlue}{cmyk}{0.96,0,0,0}
\definecolor{SkyBlue}{cmyk}{0.62,0,0.12,0}
\definecolor{Turquoise}{cmyk}{0.85,0,0.20,0}
\definecolor{TealBlue}{cmyk}{0.86,0,0.34,0.02}
\definecolor{Aquamarine}{cmyk}{0.82,0,0.30,0}
\definecolor{BlueGreen}{cmyk}{0.85,0,0.33,0}
\definecolor{Emerald}{cmyk}{1,0,0.50,0}
\definecolor{JungleGreen}{cmyk}{0.99,0,0.52,0}
\definecolor{SeaGreen}{cmyk}{0.69,0,0.50,0}
\definecolor{Green}{cmyk}{1,0,1,0}
\definecolor{ForestGreen}{cmyk}{0.91,0,0.88,0.12}
\definecolor{PineGreen}{cmyk}{0.92,0,0.59,0.25}
\definecolor{LimeGreen}{cmyk}{0.50,0,1,0}
\definecolor{YellowGreen}{cmyk}{0.44,0,0.74,0}
\definecolor{SpringGreen}{cmyk}{0.26,0,0.76,0}
\definecolor{OliveGreen}{cmyk}{0.64,0,0.95,0.40}
\definecolor{RawSienna}{cmyk}{0,0.72,1,0.45}
\definecolor{Sepia}{cmyk}{0,0.83,1,0.70}
\definecolor{Brown}{cmyk}{0,0.81,1,0.60}
\definecolor{Tan}{cmyk}{0.14,0.42,0.56,0}
\definecolor{Gray}{cmyk}{0,0,0,0.50}
\definecolor{Black}{cmyk}{0,0,0,1}
\definecolor{White}{cmyk}{0,0,0,0}


%有方框的verbatim
 % \DefineVerbatimEnvironment{fverb}{Verbatim}{gobble=2,numbers=left,numbersep=2mm,   frame=lines,framerule=0.8mm}

\DefineVerbatimEnvironment{fverb}{Verbatim}{frame=single}

%beware 
\DefineVerbatimEnvironment{vbeware}{Verbatim}%
{frame=single,
framerule=1mm,
%framesep=3mm,
rulecolor=\color{Red},
%fillcolor=\color{Yellow}%
}
\newenvironment{beware}
{\includegraphics[width=22pt,height=22pt]{icons/beware.png}
\vbeware}
{\endvbeware}

%suggestion
\DefineVerbatimEnvironment{vsuggest}{Verbatim}%
{frame=single,
framerule=1mm,
%framesep=3mm,
rulecolor=\color{SkyBlue},
%fillcolor=\color{ForestGreen}%
}
\newenvironment{suggest}
{\includegraphics[width=22pt,height=22pt]{icons/suggest.png}
\vsuggest}
{\endvsuggest}


%note

\DefineVerbatimEnvironment{vnote}{Verbatim}%
{frame=single,
framerule=1mm,
%framesep=3mm,
rulecolor=\color{Yellow},
%fillcolor=\color{Brown}%
}
\newenvironment{note}{\includegraphics[width=22pt,height=22pt]{icons/note.png}\vnote}{\endvnote}


%tips
\DefineVerbatimEnvironment{vtips}{Verbatim}%
{%
frame=single,
framerule=1mm,
%framesep=3mm,
rulecolor=\color{Violet},
%fillcolor=\color{RoyalPurple}
}
\newenvironment{tips}{\includegraphics[width=22pt,height=22pt]{icons/tips.png}\vtips}{\endvtips}

%--------------------------------------------------------
%定义code环境，用于显示c代码
\lstnewenvironment{code}{%
  \lstset{language=C,breaklines=true,%
  basicstyle=\ttfamily,%
  numbers=left,xleftmargin=2pt,xrightmargin=2pt,%
  frame=single,framerule=0.1pt,%
 % escapeinside=``,
  keywordstyle=\color{SeaGreen},
  identifierstyle=\color{Blue},
  stringstyle=\color{Magenta},
  commentstyle=\color{Cyan},
  extendedchars=false,%显示汉字
  showstringspaces=false
  }}{}
%定义latex环境，用于显示latex代码 
\lstnewenvironment{lcode}{%
  \lstset{language=TeX,breaklines=true,%
  basicstyle=\ttfamily,%
  numbers=left,xleftmargin=2pt,xrightmargin=2pt,%
  frame=single,framerule=0.1pt,%
 % escapeinside=``,
  keywordstyle=\color{SeaGreen},
   extendedchars=false,%显示汉字
  showstringspaces=false
  }}{}
\newcommand{\program}[2]{%
%两个参数，1为源文件，2为书中名称
\begin{table}[hbp]

\renewcommand{\tablename}{program}
\caption{#2\label{#2}}

\lstinputlisting[ language=C,breaklines=true,%
  basicstyle=\ttfamily,%
  numbers=left,xleftmargin=2pt,xrightmargin=2pt,%
  frame=single,framerule=0.1pt,%
  keywordstyle=\color{SeaGreen},
  identifierstyle=\color{Blue},
  stringstyle=\color{Magenta},
  commentstyle=\color{Cyan},
   extendedchars=false,%显示汉字
  showstringspaces=false
  ]{#1}
\end{table}
}{}
\newenvironment{shortstory}{

\marginpar{story~}

\begin{minipage}[t]{\textwidth-1cm}  % \centering
\shaded
}{
\endshaded
\end{minipage}
}
\newenvironment{advanced}{
\marginpar{advanced topics}

\begin{minipage}[t]{\textwidth-1cm}   % \centering
\shaded
}{\endshaded
\end{minipage}
}

\newcommand{\summary}{\section{Summary}}
\newcommand{\intro}{\section{Intro}}
%\newcommand{\exercise}[2]{\subsection{#1}\label{#2}}

\newtheorem{exercise}{习题}[chapter]

